﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; 
using System.Data;
using System.Data.SqlClient;

public partial class _jh : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    { 
        //服务器端口 8380 映射到 80
        if (Request.QueryString.Count == 0)
            return;
         
        string str = Request.QueryString["sfz"].ToString();
        if (string.IsNullOrEmpty(str))
            return;

        DataRow row = GetDataRow(str);
        if (row == null)
            return;

            LabelName.Text = row["Name"] as string;
            LabelSex.Text = (Int64)row["Sex"] == 1 ? "男" : "女";
            LabelShenFenZheng.Text = row["ShenFenZheng"] as string;
            LabelZhengShuBianHao.Text = row["ZhengShuBianHao"] as string;

            DateTime dt;
            if (DateTime.TryParseExact(row["OrderDateTime"] as string, FCNS.Data.DbDefine.dateTimeFormat, null, System.Globalization.DateTimeStyles.None, out dt))
            {
                if (dt.AddYears(1) >= DateTime.Now)
                    LabelFaZhengRiQi.Text = dt.ToString("yyyy年MM月dd日");
                else
                    LabelFaZhengRiQi.Text = "你的证书已过期";
            }
            else
                LabelFaZhengRiQi.Text = "无法查询你的继续教育记录";
    }

    private DataRow GetDataRow(string str)
    {
        DataRow row = null;
        SqlConnection connMssql = new SqlConnection("Data Source=192.168.2.1;initial catalog=doubleH;User ID=doubleH;Password=SKY555e~!");
        SqlCommand cmdMssql = new SqlCommand();
        cmdMssql.Connection = connMssql;
        connMssql.Open();
        cmdMssql.CommandText = "select * from JH where ShenFenZheng like '" + str + "'";  
        DataTable dt = new DataTable();  
        SqlDataAdapter adapter = new SqlDataAdapter(cmdMssql); 
        try
        { 
            adapter.Fill(dt);
            if (dt.Rows.Count > 0)
                row = dt.Rows[0];
        }
        catch 
        { 
        }
        finally
        {
            adapter.Dispose();
            connMssql.Close();
            connMssql.Dispose();
            cmdMssql.Dispose(); 
        }
        return row;
    }
}